package com.ruoyi.web.controller.system;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ProjectIssue;
import com.ruoyi.system.service.IProjectIssueService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 项目问题Controller
 * @author ruoyi
 * @date 2021-01-07
 */
@RestController
@RequestMapping("/system/issue")
public class ProjectIssueController extends BaseController
{
    @Autowired
    private IProjectIssueService projectIssueService;

    //查询项目问题列表
    @GetMapping("/list")
    public TableDataInfo list(Long proId)
    {
        startPage();
        List<ProjectIssue> list = projectIssueService.selectProjectIssueList(proId);
        return getDataTable(list);
    }

    //新增项目问题列表
    //@PreAuthorize("@ss.hasPermi('system:issue:add')")
    @Log(title = "新增项目问题", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProjectIssue projectIssue ,@RequestHeader("userId")Long userId)
    {
        Date issdate = projectIssue.getIssdate();
        SimpleDateFormat format =new SimpleDateFormat("yyyy");
        SimpleDateFormat format1 =new SimpleDateFormat("MM");
        projectIssue.setIssMouth(issdate);
        projectIssue.setIssYear(format.format(issdate));
        projectIssue.setUserId(userId);
        return toAjax(projectIssueService.insertProjectIssue(projectIssue));
    }

    //修改项目问题
    //@PreAuthorize("@ss.hasPermi('system:issue:edit')")
    @Log(title = "修改项目问题", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProjectIssue projectIssue)
    {
        return toAjax(projectIssueService.updateProjectIssue(projectIssue));
    }

    //删除项目问题
    //@PreAuthorize("@ss.hasPermi('system:issue:remove')")
    @Log(title = "删除项目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{issId}")
    public AjaxResult remove(@PathVariable Long issId)
    {
        return toAjax(projectIssueService.deleteProjectIssueById(issId));

    }
    //修改项目问题
    //@PreAuthorize("@ss.hasPermi('system:issue:edit')")
    @Log(title = "修改项目问题", businessType = BusinessType.UPDATE)
    @PutMapping("/update/states")
    public AjaxResult upStates(Long[] ids,String issState)
    {
        return toAjax(projectIssueService.upProjectIssueByIds(ids,issState));
    }

}
